﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace Billing.WindowsBase.CustomControls
{
    [ToolboxItem(true)]
    [DesignerAttribute(typeof(sbLBLEnumDesigner), typeof(System.ComponentModel.Design.IDesigner))]
    [DefaultEvent("Initialized")]
    [ToolboxBitmap(typeof(System.Windows.Forms.TextBox))]
    public partial class sbLBLEnum : BaseControl
    {
        public sbLBLEnum()
        {
            InitializeComponent();
        }
        public event EventHandler ValueChanged;

        #region Public Properties

        private IBaseObject baseObject;
        public IBaseObject BaseObject
        {
            get { return baseObject; }
            set
            {
                baseObject = value;
                if (baseObject == null)
                {
                   // this.txt.Text = string.Empty;
                }
                else
                {
                   // this.txt.Text = value.Name;
                }
            }
        }

        [Category("Custom")]
        public Size NameSize
        {
            get { return this.lblName.Size; }
            set { this.lblName.Size = value; }
        }
        [Category("Custom")]
        public string NameText
        {
            get { return this.lblName.Text; }
            set { this.lblName.Text = value; }
        }

        [Bindable(true), Browsable(true)]
        public object Value
        {
            get { return this.cmb.Value; }
            set { this.cmb.Value = value; }
        }

        public object DataSource
        {
            get { return this.cmb.DataSource; }
            set { this.cmb.DataSource = value; }
        }
        [Category("Custom")]
        public bool ReadOnly
        {
            get { return this.cmb.ReadOnly;  }
            set { this.cmb.ReadOnly = value; }
        }
        [Category("Custom")]
        public Infragistics.Win.ButtonDisplayStyle DropDownButtonDisplayStyle
        {
            get { return this.cmb.DropDownButtonDisplayStyle; }
            set { this.cmb.DropDownButtonDisplayStyle = value; }
        }
        [Bindable(true), Browsable(true), Category("Custom")]
        public Infragistics.Win.DropDownStyle DropDownStyle
        {
            get { return this.cmb.DropDownStyle; }
            set { this.cmb.DropDownStyle = value; }
        }
        public int SelectedIndex
        {
            get { return this.cmb.SelectedIndex; }
            set { this.cmb.SelectedIndex = value; }
        }

         [Category("Custom")]
        public bool ShowOverflowIndicator
        {
            get { return this.cmb.ShowOverflowIndicator; }
            set { this.cmb.ShowOverflowIndicator = value; }
        }
        [Category("Custom")]
        public int DropDownListWidth
        {
            get { return this.cmb.DropDownListWidth; }
            set { this.cmb.DropDownListWidth = value; }
        }

        public string ComboText
        {
            get { return this.cmb.Text; }
            set { this.cmb.Text = value; }
        }
        #endregion

        private void cmb_ValueChanged(object sender, EventArgs e)
        {
            if(this.ValueChanged !=null)
                this.ValueChanged(sender,e);
        }




        #region Label
        [Category("Custom")]
        public override string LabelText
        {
            get { return this.lblName.Text; }
            set
            {
                this.lblName.Text = value;
                if (this.LabelAutoSize)
                {
                    AutoSizeLabel();
                }
            }
        }

        private void AutoSizeLabel()
        {
            System.Drawing.Graphics gr = this.CreateGraphics();
            this.lblName.Size = new Size((int)gr.MeasureString(this.lblName.Text, this.lblName.Font).Width + 8, this.lblName.Height);
        }
        [Category("Custom")]
        public override bool LabelAutoSize
        {
            get
            {
                return base.LabelAutoSize;
            }
            set
            {
                base.LabelAutoSize = value;
                if (this.LabelAutoSize)
                {
                    AutoSizeLabel();
                }
            }
        }
        [Category("Custom")]
        public override Size LabelSize
        {
            get { return this.lblName.Size; }
            set { this.lblName.Size = value; }
        }
        [Category("Custom")]
        public override bool LabelVisible
        {
            get { return this.lblName.Visible; }
            set { this.lblName.Visible = value; }
        }

        public override Color LabelBorderColor
        {
            get { return this.lblName.Appearance.BorderColor; }
            set { this.lblName.Appearance.BorderColor = value; }
        }
        #endregion

        #region Editor
        [Category("Custom")]
        public override string EditorText
        {
            get { return this.cmb.Text; }
            set { this.cmb.Text = value; }
        }
        [Category("Custom")]
        public override Size EditorSize
        {
            get { return this.cmb.Size; }
            set { this.cmb.Size = value; }
        }
        [Category("Custom")]
        public override bool EditorVisible
        {
            get { return this.cmb.Visible; }
            set { this.cmb.Visible = value; }
        }
        [Category("Custom")]
        public override object EditorSource
        {
            get { return cmb.DataSource; }
            set { cmb.DataSource=value; }
        }
        [Category("Custom")]
        public override object EditorValue
        {
            get { return this.cmb.Value; }
            set { this.cmb.Value = value; }
        }
        [Category("Custom")]
        public override bool EditorIsReadOnly
        {
            get{return this.cmb.ReadOnly;}
            set{this.cmb.ReadOnly = value;}
        }
        #endregion
    }




    #region "Designer
    public class sbLBLEnumDesigner : System.Windows.Forms.Design.ControlDesigner
    {
        public override System.Windows.Forms.Design.SelectionRules SelectionRules
        {
            get
            {
                System.Windows.Forms.Design.SelectionRules i = System.Windows.Forms.Design.SelectionRules.RightSizeable |
                    System.Windows.Forms.Design.SelectionRules.Visible |
                    System.Windows.Forms.Design.SelectionRules.LeftSizeable |
                    System.Windows.Forms.Design.SelectionRules.Moveable;

                return i;
            }
        }
    }
    #endregion
}
